//
//  Freebase.h
//  Freebase
//
//  Created by Alec Flett on 7/26/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FreebaseRequest.h"
#import "FreebaseDelegate.h"

@class FreebaseSession;

@protocol FreebaseSessionDelegate

-(void)beginActivity:(FreebaseSession*)session;

-(void)endActivity:(FreebaseSession*)session;

@end


@interface FreebaseSession : NSObject {
    NSString *hostname;
    NSMutableArray *_sessionDelegates;
    
    // weak
    NSMutableArray *_outstandingRequests;
}

@property(nonatomic, retain) NSString* hostname;

+ (FreebaseSession*)session;

- (FreebaseSession *)initWithHostname: (NSString*)hostname;

// with delegate and selector
- (id <FreebaseRequest>)mqlread:(id)query 
                           name:(NSString*)name 
                       delegate: (id) delegate
              didFinishSelector:(SEL)finishedSelector;

// using cursor
- (id <FreebaseRequest>)mqlread:(id)query 
                           name:(NSString*)name 
                       delegate: (id) delegate 
              didFinishSelector:(SEL)finishedSelector
                         cursor:(id)cursor;

+ (NSString*)urlForMqlread:(id)query;
+ (NSString*)urlForMqlread:(id)query name:(NSString*)name;
+ (NSString*)urlForMqlread:(id)query name:(NSString*)name options:(NSDictionary*)options;

// everything
- (id <FreebaseRequest>)mqlread:(id)query 
                name:(NSString*)name 
            delegate:(id) delegate 
   didFinishSelector:(SEL)finishedSelector
             options:(NSDictionary*)options;

// mqlwrite
- (id <FreebaseRequest>)mqlwrite:(id)query 
                            name:(NSString*)name 
                        delegate: (id) delegate
               didFinishSelector:(SEL)finishedSelector;


// search
- (id <FreebaseRequest>)search:(id)query 
               name:(NSString*)name 
           delegate: (id) delegate
  didFinishSelector:(SEL)finishedSelector;

// search
- (id <FreebaseRequest>)search:(id)query 
               name:(NSString*)name 
           delegate: (id) delegate
  didFinishSelector:(SEL)finishedSelector
            options:(NSDictionary*)options;

// geosearch
- (id <FreebaseRequest>)geosearch:(id)location
                             name:(NSString*)name
                         delegate:(id)delegate
                didFinishSelector:(SEL)finishedSelector;

- (id <FreebaseRequest>)geosearch:(id)location
                             name:(NSString*)name
                         delegate:(id)delegate
                didFinishSelector:(SEL)finishedSelector
                          options:(NSDictionary*)options;

+ (NSString*) urlForSearch:(id)query;
+ (NSString*) urlForSearch:(id)query name:(NSString*)name;
+ (NSString*) urlForSearch:(id)query name:(NSString*)name options:(NSDictionary*)options;

// touch
- (id <FreebaseRequest>)touch;
- (id <FreebaseRequest>)touch: (NSString*)name 
          delegate:(id)delegate
 didFinishSelector:(SEL)finishedSelector;

// blurb
- (id <FreebaseRequest>)blurb:(NSString*)content_id 
              name:(NSString*)name 
          delegate:(id)delegate
 didFinishSelector:(SEL)finishedSelector;

- (id <FreebaseRequest>)blurb:(NSString*)content_id 
              name:(NSString*)name 
          delegate:(id)delegate
 didFinishSelector:(SEL)finishedSelector
           options:(NSDictionary *)options;

// imageThumb
- (id <FreebaseRequest>)imageThumb:(NSString*)image_id
                   name:(NSString*)name 
               delegate:(id)delegate 
      didFinishSelector:(SEL)finishedSelector
                options:(NSDictionary*)options;

- (NSString*)urlForImageThumb:(NSString*)image_id
                      options:(NSDictionary*)options;

- (id <FreebaseRequest>)login:(NSString*)user_id
                     password:(NSString*)password
                     delegate:(id)delegate 
            didFinishSelector:(SEL)finishedSelector;

// writing methods

- (id <FreebaseRequest>)uploadImage:(UIImage*)image
                        contentType:(NSString*)contentType
                              topic:(NSString*)topicId
                           delegate:(id)delegate
                  didFinishSelector:(SEL)finishedSelector
                            options:(NSDictionary*)options;

-(void)addSessionDelegate:(id<FreebaseSessionDelegate>) delegate;
-(void)removeSessionDelegate:(id<FreebaseSessionDelegate>) delegate;

// private, only called by helper classes
-(void)beginRequest:(id<FreebaseRequest>)request;
-(void)endRequest:(id<FreebaseRequest>)request;


@end


